{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">

    <!-- <div class="demoTable layui-row">
		<button class="layui-btn" style="margin-left:30px;margin-top:15px;" id="search" data-type="reload">{:lang('search')}</button>
		<a href="{:url('index')}" style="margin-top:15px;" class="layui-btn">{:lang('reset')}</a>
		
	</div> -->
    <blockquote class="layui-elem-quote">
        <a href="{:url('powerAdd')}" class="layui-btn layui-btn-small">添加会员权益</a>
    </blockquote>
    <!-- 这个是列表  -->
    <table class="layui-table" id="list" lay-filter="list"></table>

</div>

{include file="common/foot"/}

<script type="text/html" id="action">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">{:lang('edit')}</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
</script>
<script type="text/html" id="logo">
    <img src="{{d.logo}}" alt="" style="width:80%;height:100%;">
</script>
<script type="text/html" id="status">
    {{# if(d.status==0){ }}
    <input type="checkbox" data_id="{{d.id}}" name="status" lay-skin="switch" lay-text="正常|下架" value="{{d.status}}" checked lay-filter="status">
    {{# }else{ }}
    <input type="checkbox" name="status" data_id="{{d.id}}" lay-skin="switch" lay-text="正常|下架" value="{{d.status}}" lay-filter="status">
    {{# } }}
</script>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#test10'
            , type: 'datetime'
            , range: true
        });
    })
    // 表格js部分
    layui.use(['table', 'form'], function () {
        var table = layui.table, form = layui.form, $ = layui.jquery;
        var tableIn = table.render({
            id: 'ad',
            elem: '#list',
            url: '{:url("power")}',
            method: 'post',
            page: true,
            cols: [[
                { field: 'id', align: 'center', title: '{:lang("id")}', width: 80, fixed: true, sort: true },
                { field: 'title', align: 'center', title: '名称', width: 150, fixed: true },
                { field: 'logo', align: 'center', title: '图片', width: 130, fixed: true, toolbar: '#logo' },
                { field: 'addtime', align: 'center', title: '添加时间', width: 150, fixed: true },
                { field: 'status', align: 'center', title: '状态', width: 100, fixed: true, toolbar: '#status' },
                { width: 160, align: 'center', title: '{:lang("action")}', toolbar: '#action' }
            ]],
            limit: ''
        });


        form.on('switch(status)', function (obj) {
            loading = layer.load(1, { shade: [0.1, '#fff'] });
            var val = this.value == true ? 0 : 1;
            let id = this.getAttribute('data_id')
            $.post('{:url("powerStatus")}', { 'id': id, 'status': val }, function (res) {

                layer.close(loading);
                if (res.errorCode == 8888) {
                    layer.msg(res.msg, { time: 1000, icon: 1 });
                    //tableIn.reload();
                } else {
                    layer.msg(res.msg, { time: 1000, icon: 2 }, function () {
                        location.href = res.url;
                    });
                    return false;
                }

            })
        });
        //点击table上的按钮
        table.on('tool(list)', function (obj) {
            //获取当前点击行的数据
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定要删除该数据吗！', function (index) {
                    var loading = layer.load(1, { shade: [0.1, '#fff'] });
                    $.post("{:url('powerDel')}", { id: data.id }, function (res) {
                        layer.close(loading);
                        if (res.errorCode == 8888) {
                            layer.msg(res.msg, { time: 1000, icon: 1 });
                            obj.del();
                        } else {
                            layer.msg(res.msg, { time: 1000, icon: 2 });
                        }
                    });
                    layer.close(index);
                });
            }
            if (obj.event === 'edit') {
                location.href = `/admin/Card/powerEdit.html?id=${data.id}`

            }
        });
    });
</script>
</body>

</html>